<?php

class ErrorController extends Zend_Controller_Action {

    public function errorAction() {
        $errors = $this->_getParam('error_handler');

        switch ($errors->type) {
            // 404 error -- controller or action not found
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                $this->_forward('pagenotfound');
                break;
            default:
                $this->getResponse()->setHttpResponseCode(500);
                // lastfm error
                if (get_class($errors->exception) == 'Lastfm_Error')
                    $this->_forward('lastfm');
                else {
                    // application error
                    $this->view->message = 'Application error';
                }
                break;
        }

        // conditionally display exceptions
        if ($this->getInvokeArg('displayExceptions') == true) {
            $this->view->exception = $errors->exception;
        }


        $this->view->request = $errors->request;
    }

    public function pagenotfoundAction() {
        $this->getResponse()->setHttpResponseCode(404);
    }

    public function lastfmAction() {
        $errors = $this->_getParam('error_handler');
        $this->view->message = 'Last.fm error';
        if ($this->getInvokeArg('displayExceptions') == true) {
            $this->view->exception = $errors->exception;
        }
    }

}

